package containerlogistik.implementation;

import containerlogistik.interfaces.Mass;

public class MassInKg extends AbstractValue<Mass> implements Mass {
    
    private final double kilogramm;

    private MassInKg(double kilo) {
        this.kilogramm = kilo;
    }

    static MassInKg valueOf(double kilo) {
        return new MassInKg(kilo);
    }

    @Override
    public double kg() {
        return this.kilogramm;
    }

    @Override
    public double g() {
        return this.kg() * Values.KG_IN_GRAM;
    }

    @Override
    public double to() {
        return this.kg() * Values.KG_IN_TONNE;
    }

    @Override
    public boolean isZero() {        
        return (this.equals(Values.ZERO_MASS));
    }

    @Override
    public boolean isValid() {
        return true;
    }

    @Override
    public String toString() {
        return String.format("MassInKg{kilo=%.2f, gram=%.2f, tonne=%.2f}",
                this.kg(), this.g(), this.to());
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final MassInKg other = (MassInKg) obj;
        if (Double.doubleToLongBits(this.kg()) != Double.doubleToLongBits(other.kg())) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        return hashDouble(this.kg());
    }

    @Override
    public int compareTo(Mass o) {
        return Double.compare(this.kg(), o.kg());
    }

    @Override
    public Mass add(Mass value) {
        return Values.massInKg(this.kg() + value.kg());
    }

    @Override
    public Mass sub(Mass value) {
        return Values.massInKg(this.kg() - value.kg());
    }

    @Override
    public Mass mul(double factor) {
        return Values.massInKg(this.kg() * factor);
    }

    @Override
    public Mass div(double factor) {
        return Values.massInKg(this.kg() / factor);
    }

    @Override
    public Mass inverse() {
        return Values.massInKg(-this.kg());
    }

    @Override
    public double div(Mass value) {
        return (this.kg() / value.kg());
    }
}
